package com.leokok.jts.learning.jts.core.algorithm;

import org.junit.Test;
import org.locationtech.jts.algorithm.Orientation;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;

/**
 * 用于计算基本几何结构(包括点三重体(三角形)和环)的方向的函数。方向是平面几何的基本属性。
 */
public class OrientationTest {

    public static void main(String[] args) {
         Coordinate p0 = new Coordinate(219.3649559090992, 140.84159161824724);
         Coordinate p1 = new Coordinate(168.9018919682399, -5.713787599646864);

         Coordinate p = new Coordinate(186.80814046338352, 46.28973405831556);
         int orient = Orientation.index(p0, p1, p);
         int orientInv = Orientation.index(p1, p0, p);

        System.out.println("p在p0->p1的左侧:"+orient);
        System.out.println("p在p1->p0的右侧:"+orientInv);
    }

    @Test
    public void isCCWTest() throws ParseException {
        WKTReader wktReader = new WKTReader();
        Geometry geometry = wktReader.read("POLYGON ((415.1715 77.9175, 415.1712 77.9172, 415.1711 77.91685, 415.1717 77.9165, 415.1718 77.91649, 415.1724 77.9166, 415.1728 77.9169, 415.17286 77.91726, 415.1728 77.9176, 415.1725 77.9179, 415.1719 77.918, 415.1716 77.918, 415.1715 77.9175))");

        Coordinate[] coordinates = geometry.getCoordinates();

        System.out.println(Orientation.isCCW(coordinates));


    }
}
